﻿#ifndef NETMANGER_UDP_H
#define NETMANGER_UDP_H



#define USERMAX 50   //映射的最大用户数量
#include "QUdpSocket"



class netManger_udp
{
public:
    struct socketMsg{
        QString netHost = ""; //远程Host
        uint16_t netPort = 0; //远程端口
        uint16_t localPort = 0; //本地的服务端口
        QUdpSocket* socket = nullptr; //Udp连接的套接字
        uint32_t signNum = 0;
    };

    std::function<void(socketMsg*)> event_localReadyRead = nullptr;

private:
    QVector<socketMsg> userList; //本地客户端的连接数量
    uint32_t startNumber = 0; //当获取用户被调用以后，自动增加用户数量



public:
    netManger_udp(std::function<void(socketMsg*)> localReadyReadFun);
    ~netManger_udp();

    socketMsg getUser(QString netHost,uint16_t netPort,uint16_t localPort); //无论如何都能获取到用户指针，内部自动协调
    void clear(); //清理所有客户

    void event_readyRead(QString netHost,uint16_t netPort,uint16_t localPort,QByteArray data); //收到数据,客户端模拟转发

};

#endif // NETMANGER_UDP_H
